// index.js
// 获取应用实例
const app = getApp()
const pos = {x:0, y:0};
const endDistance = 200;

Page({
    data: {
        winHeight: 750,
        winHeight: 750,
        currentIndex: 0,
        nextUpDeg: -180,
        prevDownDeg: 180,
        list: [1,2,3]
    },

    onShow() {
        this.initPageFlip();
    },

    initPageFlip() {

    },

    touchStart(e) {
        console.log('touchStart', e);
        const ev = e.touches[0];
        pos.x = ev.pageX;
        pos.y = ev.pageY;
    },
    touchMove(e) {
        const winHeight = this.data.winHeight;
        const ev = e.touches[0];
        console.log('touchMove', e, pos);

        if(ev.pageY - pos.y < 0) {
            // 上翻
            // pos.x = ev.pageX;
            // pos.y = ev.pageY;
            console.log('上翻');
            var downDeg = ((ev.pageY - pos.y)/(winHeight/2))*(-90);
            var nextUpDeg = (2+((ev.pageY - pos.y)/(winHeight/2)))*(-90);
            this.setData({
                downDeg, nextUpDeg
            })
            console.log('xxxx', downDeg, nextUpDeg);
        }else {
            // 下翻
            // pos.x = ev.pageX;
            // pos.y = ev.pageY;
            console.log('下翻');
            var upDeg = ((ev.pageY - pos.y)/(winHeight/2))*(-90);
            var prevDownDeg = (2-((ev.pageY - pos.y)/(winHeight/2)))*(90);
            this.setData({
                upDeg, prevDownDeg
            })
            console.log('yyyy', upDeg, prevDownDeg);
        }

    },
    touchEnd(e) {
        console.log('touchEnd', e, pos);
        let currentIndex = this.data.currentIndex;
        const pageCount = this.data.list.length;
        const ev = e.changedTouches[0];
        
        if((ev.pageY - pos.y < -100) && (pageCount-currentIndex > 1)) {
            this.setData({
                currentIndex: currentIndex+1
            })
        }else if((ev.pageY - pos.y > 100) && currentIndex > 0) {
            this.setData({
                currentIndex: currentIndex-1
            })
        }else {

        }
        this.setData({
            downDeg: 0,
            upDeg: 0,
            prevDownDeg: 180,
            nextUpDeg: -180,
        })
        pos.x=0;
        pos.y=0;
    },

})